//
//  BR_View.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/4/5.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BR_View.h"
#import "BK_OD_Color.h"
#import <Masonry.h>
@implementation BR_View

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createUI];
        
    }
    return self;
}

-(void)createUI{
    
    
    _ImgV_Tip=[[UIImageView alloc]init];
    _ImgV_Tip.backgroundColor = [UIColor clearColor];
    _ImgV_Tip.contentMode = UIViewContentModeScaleToFill;
    [self addSubview:_ImgV_Tip];
    [_ImgV_Tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset((ScreenWidth-209/2.0)/2.0);
        make.left.mas_equalTo(self.mas_left).offset((ScreenHeight-371.5-17-5)/2.0);
        make.width.mas_equalTo(@(17));
        make.height.mas_equalTo(@(15));
    }];
    
    
    
    
    _lab_Tip=[[UILabel alloc]init];
    _lab_Tip.text=@"";
    _lab_Tip.textColor=kOrderCream_colored2;
    _lab_Tip.font=[UIFont systemFontOfSize:14];
    _lab_Tip.numberOfLines=0;
    _lab_Tip.textAlignment=NSTextAlignmentLeft;
    [self  addSubview:_lab_Tip];
    [_lab_Tip mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(_ImgV_Tip.mas_centerY);
        make.left.equalTo(_ImgV_Tip.mas_right).offset(5);
    }];
    
    
    
    _lab_Number=[[UILabel alloc]init];
    _lab_Number.text=@"";
    _lab_Number.textColor=kOrderBlack1;
    _lab_Number.font=[UIFont systemFontOfSize:25];
    _lab_Number.textAlignment=NSTextAlignmentCenter;
    _lab_Number.numberOfLines=0;
    [self  addSubview:_lab_Number];
    [_lab_Number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lab_Tip.mas_bottom).offset(34);
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.width.mas_equalTo(ScreenHeight-2*ApplicationBackGauge);
    }];
    
    
}

-(NSString *)hanleNums:(NSString *)num{
    
    
    
    NSString *str = num;
    NSLog(@"%@", str);
    NSMutableArray *mA = [NSMutableArray array];
    for (NSInteger i = 1; i <= 20; i++) {
        if (i <= 18) {
            [mA addObject:[str substringToIndex:1]];
            str = [str substringFromIndex:1];
        }
        if (i%5 == 0) {
            [mA insertObject:@"  " atIndex:i-1];
        }
    }
    NSString *string = [mA componentsJoinedByString:@""];
    
    
      return string;
}


-(void)relayOutBRWithNum:(NSString *)num{
    _lab_Tip.text=@"付款码数字仅用于支付时向收银员展示，请勿泄露以防诈骗";
    _lab_Number.text=[self hanleNums:num];
    _ImgV_Tip.image=[UIImage imageNamed:@"BK_PayStore_notice"];
}

+(NSString *)GetBR_Code:(NSString *)payCode{
    NSString * str1=[payCode substringToIndex: 4];
    NSString * str2=[payCode substringFromIndex:payCode.length-4];
    return [NSString stringWithFormat:@"%@******%@",str1,str2];
}

/**
 *   获取字符宽度
 */
+ (CGFloat)getWidthWithTitle:(NSString *)title font:(CGFloat )font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = [UIFont systemFontOfSize:font];
    [label sizeToFit];
    return label.frame.size.width;
}


@end
